package com.hu.zhcc.shiro.controller.junM;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.shiro.entity.junM.dto.TInterposeClassifyDTO;
import com.hu.zhcc.shiro.entity.junM.pojo.TInterposeClassify;
import com.hu.zhcc.shiro.entity.junM.vo.TInterposeClassifyVO;
import com.hu.zhcc.shiro.entity.lgx.THealthmgr;
import com.hu.zhcc.shiro.entity.lgx.TMember;
import com.hu.zhcc.shiro.entity.lgx.TSetmeal;
import com.hu.zhcc.shiro.entity.xsf.dto.TEvaluateDTO;
import com.hu.zhcc.shiro.entity.xsf.pojo.TDiseaseLibrary;
import com.hu.zhcc.shiro.entity.xsf.vo.TEvaluateVO;
import com.hu.zhcc.shiro.service.junM.InterposeClassifyService;
import com.hu.zhcc.shiro.service.lgx.TmemberService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/interposeClassify")
public class InterposeClassifyController {

    @Autowired
    private InterposeClassifyService interposeClassifyService;

    @GetMapping("")
    public ResponseEntity<Page<TInterposeClassifyVO>> queryInterposeClassifyAll(@RequestParam(required = false) String name,
                                                                                int offset, int limit){
        Map<String, Object> paremeters = new HashMap<String, Object>();
        if (!StringUtils.isBlank(name)) {
            paremeters.put("name", name);
        }
        Page<TInterposeClassifyDTO> result = this.interposeClassifyService.queryInterposeClassifyAll(paremeters,offset,limit);
        System.out.println(result);
        List<TInterposeClassifyVO> voList = new ArrayList<TInterposeClassifyVO>();
        if(result.getRows()==null){
            return ResponseEntity.ok(new Page<TInterposeClassifyVO>(result.getTotal(), voList));
        }

        for(TInterposeClassifyDTO dto : result.getRows()) {
            TInterposeClassifyVO vo = new TInterposeClassifyVO();
            BeanUtils.copyProperties(dto, vo);
            voList.add(vo);
        }
        return ResponseEntity.ok(new Page<TInterposeClassifyVO>(result.getTotal(), voList));
    }

    @GetMapping("/{id}")
    public ResponseEntity<TMember> getById(@PathVariable("id") int id){
        TMember dto = this.interposeClassifyService.getId(id);
        if(dto == null) {
            return ResponseEntity.notFound().build();
        }
        TMember vo = new TMember();
        BeanUtils.copyProperties(dto, vo);
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/getSetmealById/{id}")
    public ResponseEntity<TSetmeal> getSetmealById(@PathVariable("id") int id){
        TSetmeal dto = this.interposeClassifyService.getSetmealById(id);
        if(dto == null) {
            return ResponseEntity.notFound().build();
        }
        TSetmeal vo = new TSetmeal();
        BeanUtils.copyProperties(dto, vo);
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/getCheckListInit")
    public List<TDiseaseLibrary> getCheckListInit(){

        List<TDiseaseLibrary> dtoList = this.interposeClassifyService.getCheckListInit();

        return dtoList;
    }

    @GetMapping("/getSelectListInit")
    public List<THealthmgr> getSelectListInit(){

        List<THealthmgr> dtoList = this.interposeClassifyService.getSelectListInit();

        return dtoList;
    }

    @PutMapping("/{id}/{diseaseIds}/{healthName}")
    public void updateDiseaseLibrary(@PathVariable("id") Integer id,
                                     @PathVariable("diseaseIds") List<String> diseaseIds,
                                     @PathVariable("healthName") String healthName){
        System.out.println(id);
        System.out.println(diseaseIds.toString());
        System.out.println(healthName);

        this.interposeClassifyService.updateDiseaseLibrary(id,diseaseIds,healthName);

    }
}
